#include "FTLorentzVector.h"

bool TLV_compare_Pt(const TLorentzVector &a, const TLorentzVector &b)
{
	return a.Pt() > b.Pt();
}

bool TLV_compare_Mass(const TLorentzVector &a, const TLorentzVector &b)
{
	return a.M() > b.M();
}


double TLV_M(const TLorentzVector &a, const TLorentzVector &b){
	TLorentzVector add(0,0,0,0);

	add = a+b;
	float mass_comb=add.M();
	return(mass_comb);
}

double TLV_Mt(const TLorentzVector &a, const TLorentzVector &b){
	TLorentzVector add(0,0,0,0);

	add = a+b;
	add.SetPz(0);
	float mt_comb=add.M();//in LTV,  .Mt is calculated by E^2-pz^2,  not by px^2+py^2, so not use it.
	return(mt_comb);
}

double TLV_Pt(const TLorentzVector &a, const TLorentzVector &b){
	TLorentzVector add(0,0,0,0);

	add = a+b;
	float pt_comb=add.Pt();
	return(pt_comb);
}


double TLV_Eta(const TLorentzVector &a, const TLorentzVector &b){
	TLorentzVector add(0,0,0,0);

	add = a+b;
	float eta_comb=add.Eta();
	return(eta_comb);
}

std::ostream & operator<<(std::ostream & ostr, const TLorentzVector &p){
	printf("\n"); // ]label the columns
	printf("%12s %12s %12s %12s %12s %12s %12s %12s \n","x","y","z","e", "rapidity", "phi", "pt","m" ); // label the columns
	printf("%12.5f %12.5f %12.5f %12.5f %12.5f %12.5f %12.5f %12.5f  \n", p.Px(),p.Py(),p.Pz(),p.E(), p.Rapidity(),p.Phi(),p.Pt(),p.M());
	return ostr;
}

std::ostream & operator<<(std::ostream & ostr, const std::vector<TLorentzVector> & p){

	printf("\n"); // label the columns
	TLorentzVector total(0,0,0,0);
	if (p.size() == 0) return ostr;

	printf("%12s, %12s %12s %12s %12s %12s %12s %12s %12s \n","TLorentz#", "x","y","z","e", "rapidity", "phi", "pt","m" ); // label the columns
	for(unsigned int i=0;i<p.size();i++){
		printf("%12u, %12.5f %12.5f %12.5f %12.5f %12.5f %12.5f %12.5f %12.5f  \n", i, p[i].Px(),p[i].Py(),p[i].Pz(),p[i].E(), p[i].Rapidity(),p[i].Phi(),p[i].Pt(),p[i].M());
		total = total +p[i];
	}

	if(p.size()>1){
		printf("%12s, %12.5f %12.5f %12.5f %12.5f %12.5f %12.5f %12.5f %12.5f  \n","total", total.Px(),total.Py(),total.Pz(),total.E(), total.Rapidity(),total.Phi(),total.Pt(),total.M());
	}

	return ostr;
}
